package com.yindian.cos.monitor.properties;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 自动化span信息配置
 *
 * @author zhangchuanhao
 * @create 2018/11/4
 */
@Data
@Component
public class MonitorSpanProperties {
    /**
     * 服务端口
     */
    @Value("${server.port}")
    private int port;

    /**
     * 项目名称
     */
    @Value("${spring.application.name}")
    private String serverName;

    /**
     * 节点名称，默认为ip:port
     */
    private String node;

    public String getNode() {
        String ip;
        try {
            InetAddress address = InetAddress.getLocalHost();
            ip = address.getHostAddress();
        } catch (UnknownHostException e) {
            ip = "UnknownHost";
        }
        if (StringUtils.isBlank(node)) {
            node = ip + ":" + port;
        }
        return node;
    }
}
